<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.meila.cms.entity.User"%>

<%
	User user=((User) session.getAttribute("loginUser"));

%>

<!DOCTYPE HTML>
<html lang="zh-CN">
<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>新建设计</title>
<%@ include file="../common/common.jsp"%>

</head>

<body class="client-body">
	<jsp:include page="../common/client-head.jsp"></jsp:include>

	<div class="client-content">
		<jsp:include page="../common/client-leftMenu-part.jsp"></jsp:include>

		<div class="client-contentBox">
			<div class="newDedign-content">
				<div class="newDedign-head">新建设计</div>
			</div>

			<form class="form-horizontal newDedign-content"
				style="display: block;">
				<div class="form-group">
					<label class="col-sm-2 control-label">名称</label>
					<div class="col-sm-7">
						<input type="text" class="form-control" name="designame"
							id="designname" onblur="designameVerify(<%=user.getId()%>)"/>
					</div>
					<div class="col-sm-3" onclick="create()">
						<a class="btn btn2 a-white"  id="btn">创建</a>
					</div>
				</div>

				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-10">
						<c:if test="${user.remianSpace<0}">
							<i class="fa fa-unlock-alt"></i>私有空间不足，您只能创建公开文件，您也可以扩容
						</c:if>
					</div>
				</div>
			</form>

		</div>
	</div>
	<script type="text/javascript">
		function create() {
			if($('#designname').val()==""){
		       jAlert("设计名不能为空","提示");
		       return false;
		  	}
		  	if($('#designname').val().length > 20){
		       jAlert("设计名不能超过20个字符","提示");
		       return false;
		  	}
				
				$.ajax({
					type : "POST",
					url : CONTEXT_PATH+'front/partDesign/addPartDesign?designame='+$('#designname').val(),
					dataType : "json",
					cache : false,
					async : false,
					success : function(data) {
						if (data.result==false) {
							alert(data.msg);
							$("#btn").attr("href","front/partDesign/newDesign");
						}else{
							$("#btn").attr("href","front/partDesign/partDesignModify?designame="+$('#designname').val());
						}
					}
				});
		};
		
		function designameVerify(userid){
			var designame=$("#designname").val();
			$.ajax({
				type : "POST",
				url : CONTEXT_PATH+'front/partDesign/designameVerifyInNewDesign?designame='+designame+'&userid='+userid,
				dataType : "json",
				cache : false,
				async : false,
				success : function(data){
					if(data.result == false){
						$("#designname").val('');
						jAlert("该文件名已存在!","提示");
					}
				}
			});
		};
	</script>
</body>
</html>
